package BinarySearch;

class BinarySearchBasic {
  int fn(int arr[], int target) {
    int i = 0, j = arr.length - 1; // 设置两端的指针
    while (i <= j) {
      int mid = (i + j) >>> 1; // 使用逻辑右移, 防止整数溢出
      if (arr[mid] < target) {
        i = mid + 1;
      } else if (target < arr[mid]) {
        j = mid - 1;
      } else {
        return mid;
      }
    }
    return -(i + 1);
  }
}
